<%@ page contentType="text/html;charset=UTF-8" language="java"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>

<%@ taglib tagdir="/WEB-INF/tags" prefix="t"%>

<t:body title="Редактивование профиля">

	<c:choose>
		<c:when test="${user.id ne -1}">
			<c:url value="/user/${user.id}/edit" var="url" />
			<c:set var="title" value="Редактирование профиля" />
		</c:when>
		<c:otherwise>
			<c:url value="/user/new" var="url" />
			<c:set var="title" value="Редактирование пользователя" />
		</c:otherwise>
	</c:choose>
	<div class="c_block">
	<div class="title"><c:out value="${title}" /></div>
	<form:form modelAttribute="user" enctype="multipart/form-data"
		acceptCharset="UTF-8" action="${url}">
		<fmt:formatDate value="${user.dateOfBirth}" pattern="dd.MM.yyyy"
			var="dateOfBirth" />
		<fmt:formatDate value="${user.dateOfExpulsion}" pattern="dd.MM.yyyy"
			var="dateOfExpulsion" />
		<fmt:formatDate value="${user.dateAccepted}" pattern="dd.MM.yyyy"
			var="dateOfAccepted" />

		<div class="section_name">Личные данные</div> 

		<t:input name="Фамилия *" path="user.lastName">
			<form:input path="lastName" size="20" maxlength="20" />
		</t:input>

		<t:input name="Имя *" path="user.firstName">
			<form:input path="firstName" size="20" maxlength="20" />
		</t:input>

		<t:input name="Отчество" path="user.patrName">
			<form:input path="patrName" size="20" maxlength="20" />
		</t:input>

		<t:input name="Логин *" path="user.login">
			<form:input path="login" size="20" maxlength="20" />
		</t:input>

		<t:input name="E-mail адрес" path="user.mail">
			<form:input path="mail" size="20" maxlength="20" />
		</t:input>

		<t:input name="Дата рождения" path="user.dateOfBirth">
			<input type="text" name="dateOfBirth" value="${dateOfBirth}"
				size="10" maxlength="10" class="date_input" />
		</t:input>

		<t:input name="Номер телефона" path="user.phoneNumber">
			<form:input path="phoneNumber" size="15" maxlength="15" />
		</t:input>

		<div class="photo_block row">
		<div class="simple_l">Фото(1 мб максимум)</div>
		<div class="simple_r"><input type="file" name="photoFile"
			class="file_input" border="0"></div>
		</div>
		<div class="section_name">Описание</div>

		<t:input name="Студент" path="user.student">
			<form:checkbox path="student"
				onclick="slide('.student_block', !$(this).attr('checked'), 'slow');" />
		</t:input>

		<t:input name="Преподаватель" path="user.prepod">
			<form:checkbox path="prepod" />
		</t:input>

		<t:input name="Админ" path="user.admin">
			<form:checkbox path="admin" />
		</t:input>
		
		<t:input name="Активный" path="user.enabled">
			<form:checkbox path="enabled" />
		</t:input>

		<div
			class="${user.student ? '' : 'hiden '}student_block logical_conteiner">
		<div class="section_name">Студент</div> 
		<t:input
			name="Характеристика" path="user.testimonial">
			<form:textarea path="testimonial" cols="30" rows="5" />
		</t:input> <t:input name="Группа в университете" path="user.universityGroup">
			<form:input path="universityGroup" size="20" maxlength="20" />
		</t:input> <t:input name="Год выпуска" path="user.graduationYear">
			<form:input path="graduationYear" size="4" maxlength="4" />
		</t:input> <t:input name="Группа *" path="user.group">
			<form:select path="group">
				<form:option value="">&nbsp</form:option>
				<form:options items="${groups}" itemValue="id" />
			</form:select>
		</t:input> <t:input name="Статус" path="user.status">
			<form:select path="status" items="${statuses}" itemLabel="caption"
				id="status" cssClass="status_link"
				onchange="display('.on_expulsion', $(this).val() == 'EXPULSION');" />
		</t:input>
		<div
			class="${user.status.caption eq 'Отчислен' ? '' : 'hiden '}on_expulsion logical_conteiner">
		<t:input name="Дата отчисления" path="user.dateOfExpulsion">
			<input type="text" name="dateOfExpulsion" value="${dateOfExpulsion}"
				size="10" maxlength="10" class="date_input" />
		</t:input></div>

		<t:input name="Принят в ПрофИТсофт" path="user.accepted">
			<form:checkbox path="accepted" onclick="replaceAccepted(this.checked,'.on_accepted', '.on_not_accepted');" />
		</t:input>

		<div
			class="${user.accepted ? '' : 'hiden '}on_accepted logical_conteiner">
		<t:input name="Дата принятия" path="user.dateOfExpulsion">
			<input type="text" name="dateAccepted" value="${dateOfAccepted}"
				size="10" maxlength="10" class="date_input on_accept" />
		</t:input></div>

		<div class="${user.accepted ? 'hiden ' : ''}on_not_accepted"
			style="float: left;"><t:input name="Текушее место работы"
			path="user.currentPlaceOfEmployment">
			<form:input path="currentPlaceOfEmployment" size="20"
				cssClass="on_not_accept" />
		</t:input></div>

		</div>

		<div class="section_name link"
			onclick="slide('.change_passwor_block', $('.change_passwor_block').css('display') != 'none', 'fast');">Изменение пароля</div>
		<spring:bind path="password">
			<div class="${status.error || user.id < 1 ? 'change_passwor_block' : 'change_passwor_block hiden'} logical_conteiner">
			<c:if test="${status.error}">
				<c:forEach items="${status.errorMessages}" var="msg">
					<div class="error"><c:out value="${msg}" /></div>
				</c:forEach>
			</c:if> <c:if test="${user.id ne -1}">
				<div class="row">
				<div class="simple_l">Старый пароль</div>
				<div class="simple_r"><input type="password"
					name="oldPassword" size="20" maxlength="20" /></div>
				</div>
			</c:if>
			<div class="row">
			<div class="simple_l">Новый пароль</div>
			<div class="simple_r"><form:password path="password" size="20"
				maxlength="20" /></div>
			</div>
			<div class="row">
			<div class="simple_l">А ну еще разок</div>
			<div class="simple_r"><input type="password" name="rePassword"
				size="20" maxlength="20" /></div>
			</div>
			</div>
		</spring:bind>

	</form:form> 
		<span class="last">
			<span class="link" onclick="document.forms[0].submit();" style="paddind: 5px 15px;">Сохранить</span>
			<span class="link" onclick="history.back()">Назад</span>
		</span>
	</div>
	<br />
</t:body>